package org.pro.core.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.resource.WebJarsResourceResolver;

/**
 * webMvc配置
 * 
 * @author luoqiz
 *
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurationSupport {

	@Override
	protected void addInterceptors(InterceptorRegistry registry) {
		// 注册自定义拦截器，添加拦截路径和排除拦截路径
		//registry.addInterceptor(new InterceptorConfig()).addPathPatterns("/api/**")/*.excludePathPatterns("/api/**")*/;
		super.addInterceptors(registry);
	}

	@Override
	protected void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**");
		super.addCorsMappings(registry);
	}

	@Override
	protected void addResourceHandlers(ResourceHandlerRegistry registry) {
		super.addResourceHandlers(registry);
		//spring boot 默认的资源位置配置
		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/","classpath:/public/","classpath:/resources/","classpath:/META-INF/resources/");
		registry.addResourceHandler("/**/favicon.ico").addResourceLocations("classpath:/**/favicon.ico");
		registry.addResourceHandler("/webjars/**").addResourceLocations("/webjars/")  
        .resourceChain(false)  
            .addResolver(new WebJarsResourceResolver())  
            .addResolver(new PathResourceResolver());  
	}

}
